﻿@model string[]
@using (Html.BeginForm("Create", "Security"))
{ 
    @Html.AntiForgeryToken()
    <table>
        <tr>
            <td colspan="2">
                @Html.ValidationSummary()
            </td>
        </tr>
        <tr>
            <td>
                @Ajax.Dna().TextBox("NewRoleName").Width(190).IconImageUrl(Url.Content("~/content/images/users_16.png")).GetHtml()
            </td>
            <td>
                @Ajax.Dna().Button().Name("btnAddNewRole").LocText("RES_ADD").Submit().ImageIcons(Url.Content("~/content/images/add.png")).GetHtml()
            </td>
        </tr>
    </table>
 
    @(Ajax.Dna().ListBox("RoleList1")
                       .Width(270)
                       .Options(opts =>
                       {
                           opts.OnItemSelected = "_getRoleDetail(ui.value)";
                       })
                       .Bind(Model)
                       .ItemTemplate(@<text>
    <table cellpadding="3" style="width: 100%;">
        <tr>
            <td>
                <a href="javascript:void(0);" style="color: #000000;">
                    <img src="@(Url.Content("~/content/images/" + (item.Value.ToString().Equals("administrators", StringComparison.OrdinalIgnoreCase) ? "icon_administrator_16.png" : (item.Value.ToString().Equals("guests", StringComparison.OrdinalIgnoreCase) ? "icon_guest_16.png" : "icon_users_16.png"))))" style="float: left; margin-right:2px;" alt="" />
                    @item.Title
                </a>
            </td>
            <td style="width: 20px;">
                @if ((!item.Value.ToString().Equals("administrators", StringComparison.OrdinalIgnoreCase)) && (!item.Value.ToString().Equals("guests", StringComparison.OrdinalIgnoreCase)))
                {
                    @Ajax.Dna().Button().ChangeType(ButtonTypes.ImageButton).Images(Url.Content("~/content/images/icon_delete.gif")).Click("_deleteRole(\"" + Server.UrlEncode(item.Value.ToString()) + "\",\"" + string.Format(Html.Global("RES_CONFIRMROLEDELETE"), Server.UrlEncode(item.Title)) + "\");").GetHtml()
                }
            </td>
        </tr>
    </table>
    </text>).GetHtml()
     )
}
<script type="text/javascript">
    function _getRoleDetail(_role){
    var _target= $("#permissionView");
       $.ajax({
          type:"GET",
          url:"@Url.Action("RoleDetail", "Security")",
          data:{role:_role},
          beforeSend:function(){_target.html(""); _target.addClass("d-big-loader")},
          success:function(htm){ _target.html(htm);},
          complete:function(){_target.removeClass("d-big-loader")}
       });
    }

    function _deleteRole(_val,_msg) {
       $dna.confirm("@Html.Global("QESTION")",_msg,function(){
       $.post("@Url.Action("Delete", "Security")",{ roleName : _val },function(){
        location.reload();
        });
       });
    }
</script>
@Html.StartupScripts()
